//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "NullPayoff.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/Payoff.h>
using namespace Cephei::QL;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::CNullPayoff::CNullPayoff (boost::shared_ptr<QuantLib::NullPayoff>& childNative, Object^ owner) : CPayoff(CNullPayoff::typeid)
{
#ifdef HANDLE
	_phNullPayoff = NULL;
#endif
	_ppNullPayoff = &childNative;
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppNullPayoff));
}
Cephei::QL::Instruments::CNullPayoff::CNullPayoff (QuantLib::NullPayoff& childNative, Object^ owner) : CPayoff(CNullPayoff::typeid)
{
#ifdef HANDLE
	_phNullPayoff = NULL;
#endif
	_ppNullPayoff = new boost::shared_ptr<QuantLib::NullPayoff> (&childNative);
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppNullPayoff));
    _NullPayoffOwner = owner;
    _PayoffOwner = owner;
}

Cephei::QL::Instruments::CNullPayoff::CNullPayoff (CNullPayoff^ copy) : CPayoff(CNullPayoff::typeid)
{
#ifdef HANDLE
	_phNullPayoff = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppNullPayoff = new boost::shared_ptr<QuantLib::NullPayoff> (copy->GetShared());
        _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppNullPayoff));
    }
}
Cephei::QL::Instruments::CNullPayoff::CNullPayoff (System::Type^ t) : CPayoff(CNullPayoff::typeid)
{
#ifdef HANDLE
	_phNullPayoff = NULL;
#endif
	if (!t->IsSubclassOf(CNullPayoff::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CNullPayoff::CNullPayoff (QuantLib::Handle<QuantLib::NullPayoff>& childNative, Object^ owner)  : CPayoff(CNullPayoff::typeid)
{
	_phNullPayoff = &childNative;
	_ppNullPayoff = &static_cast<boost::shared_ptr<QuantLib::NullPayoff>>(childNative.currentLink());
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppNullPayoff));
    _NullPayoffOwner = owner;
}
Cephei::QL::Instruments::CNullPayoff::CNullPayoff (QuantLib::Handle<QuantLib::NullPayoff> childNative)  : CPayoff(CNullPayoff::typeid)
{
	_phNullPayoff = &childNative;
	_ppNullPayoff = &static_cast<boost::shared_ptr<QuantLib::NullPayoff>>(childNative.currentLink());
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppNullPayoff));
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CNullPayoff::CNullPayoff (QuantLib::NullPayoff childNative)  : CPayoff(CNullPayoff::typeid)
{
#ifdef HANDLE
	_phNullPayoff = NULL;
#endif
	_ppNullPayoff = new boost::shared_ptr<QuantLib::NullPayoff> (new QuantLib::NullPayoff (childNative));
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppNullPayoff));
}
#endif

Cephei::QL::Instruments::CNullPayoff::~CNullPayoff ()
{
    if (_ppNullPayoff != NULL)
    {
	    delete _ppNullPayoff;
        _ppNullPayoff = NULL;
    }
}
Cephei::QL::Instruments::CNullPayoff::!CNullPayoff ()
{
    if (_ppNullPayoff != NULL)
    {
	    delete _ppNullPayoff;
    }
}
QuantLib::NullPayoff& Cephei::QL::Instruments::CNullPayoff::GetReference ()
{
    if (_ppNullPayoff == NULL) throw gcnew NativeNullException ();
	return **_ppNullPayoff;
}
boost::shared_ptr<QuantLib::NullPayoff>& Cephei::QL::Instruments::CNullPayoff::GetShared ()
{
    if (_ppNullPayoff == NULL) throw gcnew NativeNullException ();
	return *_ppNullPayoff;
}
QuantLib::NullPayoff* Cephei::QL::Instruments::CNullPayoff::GetPointer ()
{
    if (_ppNullPayoff == NULL) throw gcnew NativeNullException ();
	return &**_ppNullPayoff;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::NullPayoff>& Cephei::QL::Instruments::CNullPayoff::GetHandle ()
{
	if (_phNullPayoff == NULL)
	{
		_phNullPayoff = new Handle<QuantLib::NullPayoff> (*_ppNullPayoff);
	}
	return *_phNullPayoff;
}
#endif
bool Cephei::QL::Instruments::CNullPayoff::HasNative () 
{
	return (_ppNullPayoff != NULL);
}

String^ Cephei::QL::Instruments::CNullPayoff::Description::get ()
{
    try
    {
    	std::string _rv = (std::string)(*_ppNullPayoff)->description ( );   
        String^ _nrv = (String^)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
String^ Cephei::QL::Instruments::CNullPayoff::Name::get ()
{
    try
    {
    	std::string _rv = (std::string)(*_ppNullPayoff)->name ( );   
        String^ _nrv = (String^)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

